<%@ page language="java" import="java.util.*,java.sql.*,connBean.*" pageEncoding="utf-8"%>
<%@page import="com.jspsmart.upload.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<jsp:useBean id="db" class="connBean.ConnDB" scope="page">
</jsp:useBean>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title></title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
<% 
  request.setCharacterEncoding("utf-8");
  SmartUpload upload =new SmartUpload();
  upload.initialize(pageContext);
  upload.setMaxFileSize(2000000000);
  upload.setAllowedFilesList("jpg,JPG,gif");
  upload.setDeniedFilesList("exe,bat,jsp,js,htm,html");
  upload.upload();
  upload.save("/images");
  
  String p_id=upload.getRequest().getParameter("p_id");
  String p_name=upload.getRequest().getParameter("p_name");
  
  System.out.println(upload.getRequest().getParameter("st_id"));
  int st_id=Integer.parseInt(upload.getRequest().getParameter("st_id"));
  double p_price=Double.valueOf(upload.getRequest().getParameter("p_price"));
  int p_quantity=Integer.parseInt(upload.getRequest().getParameter("p_quantity"));
String filename1=upload.getFiles().getFile(0).getFileName();
   String filename2=upload.getFiles().getFile(1).getFileName();
   String filename3=upload.getFiles().getFile(2).getFileName();
   if(filename1.equals("")||filename1==null){
filename1=upload.getRequest().getParameter("image1");
}
   System.out.println();
   System.out.println(filename1);
if(filename2.equals("")||filename2==null){
filename2=upload.getRequest().getParameter("image2");
}
   System.out.println();
   System.out.println(filename2);
if(filename3.equals("")||filename3==null){
filename3=upload.getRequest().getParameter("image3");
}
   System.out.println();
   System.out.println(filename3);
   String filename=filename1+";"+filename2+";"+filename3;
   
   System.out.println();
   System.out.println(filename);
  String p_description=upload.getRequest().getParameter("description");
 int p_status=Integer.parseInt(upload.getRequest().getParameter("p_status"));
  String sql="";
db.OpenConn();
PreparedStatement pstmt=null;



  if(filename.equals("") ||filename==null){
   sql="update product set p_id=?, p_name=?, st_id=?, p_price=?, p_quantity=?,  p_description=?, p_status=? where p_id="+"'"+p_id+"'";
 pstmt=db.createPStmt(sql);
pstmt.setString(1,p_id);
pstmt.setString(2,p_name);
pstmt.setInt(3,st_id);
pstmt.setDouble(4,p_price);
pstmt.setInt(5,p_quantity);
pstmt.setString(6,p_description);
pstmt.setInt(7,p_status);


   System.out.println(sql);}
   else{
   sql="update product set p_id=?, p_name=?, st_id=?, p_price=?, p_quantity=?,p_image=?, p_description=?, p_status=? where p_id="+"'"+p_id+"'";
 pstmt=db.createPStmt(sql);
pstmt.setString(1,p_id);
pstmt.setString(2,p_name);
pstmt.setInt(3,st_id);
pstmt.setDouble(4,p_price);
pstmt.setInt(5,p_quantity);
pstmt.setString(6,filename);
pstmt.setString(7,p_description);
pstmt.setInt(8,p_status);

   System.out.println(sql);
   }
int result=pstmt.executeUpdate();

 if(result==1){ 
 response.sendRedirect("selectproduct.jsp");//执行插入成功跳转
 }else{
 %>
 修改失败，等待5秒后返回。
 <%
 response.setHeader("Refresh","5;URL=selectproduct.jsp");//执行插入失败跳转
 }
 db.closeConn();
%>  

  </body>
</html>